﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;

namespace Zen4SyncOrchestratorServices
{

    [ServiceContract]
    public interface IOrchestratorServices
    {
        /// <summary>
        /// Starts the Test Session whose identifier is given.
        /// </summary>
        /// <remarks>
        /// "Starts the Test Session" means calling all the Test Servers involved in the Test Session and giving to each one
        /// of them the list of Client Session it has to run.
        /// The Test Server can then start one Zen4SyncClient per Client Session.
        /// </remarks>
        /// <param name="testSessionId">Identifier of the Test Session to start.</param>
        [OperationContract]
        void StartTestSession(Guid testSessionId, string zen4SyncSymmetricKeyPassword);

        /// <summary>
        /// Reports a Client Session as unable to start because of the given error.
        /// </summary>
        /// <param name="clientSessionId">Identifier of the Client Session.</param>
        /// <param name="error">Problem while trying to start the Client Session.</param>
        [OperationContract]
        void ClientSessionUnableToStart(Guid clientSessionId, string error);

        /// <summary>
        /// The TestServer informs the Orchestrator that a ClientSession is ready to start.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="processId">Identifier of the process.</param>
        /// <param name="dateTime">Date and time when the ClientSession is ready to start.</param>
        [OperationContract]
        void ClientSessionIsReadytoStart(Guid clientSessionId, int processId, DateTime dateTime);

        /// <summary>
        /// The TestServer informs the Orchestrator that a ClientSession is started.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="dateTime">Date and time when the ClientSession is started.</param>
        [OperationContract]
        void ClientSessionStarted(Guid clientSessionId, DateTime dateTime);

        /// <summary>
        /// The TestServer informs the Orchestrator that a ClientSession ended its work.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="dateTime">Date and time when the ClientSession ended its work.</param>
        [OperationContract]
        void ClientSessionEndedSuccessfully(Guid clientSessionId, DateTime dateTime);

        /// <summary>
        /// The TestServer informs the Orchestrator that a ClientSession ended its work with an error.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="dateTime">Date and time when the ClientSession ended its work with an error.</param>
        /// <param name="exceptionMessage">Error message.</param>
        [OperationContract]
        void ClientSessionEndedWithError(Guid clientSessionId, DateTime dateTime, string exceptionMessage);

        /// <summary>
        /// The Console informs the Orchestrator that an activity of a ClientSession is started.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="dateTime">Date and time when the activity starts.</param>
        [OperationContract]
        void ActivityStarted(Guid clientSessionId, Guid activityId, DateTime dateTime);

        /// <summary>
        /// The Console informs the Orchestrator that an activity of a ClientSession is ended.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="dateTime">Date and time when the activity ends.</param>
        [OperationContract]
        void ActivityEndedSuccessfully(Guid clientSessionId, Guid activityId, DateTime dateTime);

        /// <summary>
        /// The Console informs the Orchestrator that an activity of a ClientSession is ended with an error.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="dateTime">Date and time when the activity ends with an error.</param>
        /// <param name="exceptionMessage">Error message.</param>
        [OperationContract]
        void ActivityEndedWithError(Guid clientSessionId, Guid activityId, DateTime dateTime, string exceptionMessage);

        /// <summary>
        /// The Console logs the execution context of a mefExecution to the Orchestrator.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="metadata">Metadata of the activity.</param>
        [OperationContract]
        void LogMefExecution(Guid clientSessionId, Guid activityId, string metadata);

        /// <summary>
        /// The Console logs the execution context of a sqlceExcution to the Orchestrator.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="sqlceExecutionContext">Execution context of the sqlceExecution.</param>
        [OperationContract]
        void LogSqlCEExecution(Guid clientSessionId, Guid activityId, Zen4SyncPOCO.POCO.SQLCEExecution.SqlceExecutionContext sqlceExecutionContext);

        /// <summary>
        /// The Console logs the execution context of a sqlServerExecution to the Orchestrator.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="sqlServerExecutionContext">Execution context of the sqlServerExecution.</param>
        [OperationContract]
        void LogSqlServerExecution(Guid clientSessionId, Guid activityId, Zen4SyncPOCO.POCO.SQLServerExecution.SqlServerExecutionContext sqlServerExecutionContext);

        /// <summary>
        /// The Console logs the SQLCE database to the Orchestrator.
        /// </summary>
        /// <param name="clientSessionId">Unique identifier of the ClientSession.</param>
        /// <param name="activityId">Unique identifier of the activity.</param>
        /// <param name="sqlCeDatabase">sqlceDatabase .sdf file.</param>
        [OperationContract]
        void LogBackupActivity(Guid clientSessionId, Guid activityId, byte[] sqlCeDatabase);

        /// <summary>
        /// Duplicate a TestSession with its ClientSessions and ActivityContext related to the ClientSessions.
        /// </summary>
        /// <param name="testSessionId">Unique identifier of the TestSession.</param>
        /// <param name="scheduledStartDateTime">Date and time when the new TestSession must run.</param>
        /// <param name="newTestSessionId">Unique identifier of the new TestSession (could be NULL).</param>
        /// <param name="newTestSessionName">Name of the new TestSession (could be NULL).</param>
        /// <param name="newTestSessionCreatedOn">Date and Time when the TestSession was duplicated.</param>
        [OperationContract]
        Guid DuplicateTestSession( Guid testSessionId, DateTime scheduledStartDateTime, Guid newTestSessionId, string newTestSessionName, DateTime newTestSessionCreatedOn);

        /// <summary>
        /// Duplicate a TestSession with its ClientSessions and ActivityContext related to the ClientSessions.
        /// </summary>
        /// <param name="testSessionId">Unique identifier of the TestSession.</param>
        /// <param name="seconds"></param>
        /// <param name="newTestSessionId">Unique identifier of the new TestSession (could be NULL).</param>
        /// <param name="newTestSessionName">Name of the new TestSession (could be NULL).</param>
        /// <param name="newTestSessionCreatedOn">Date and Time when the TestSession was duplicated.</param>
        [OperationContract]
        Guid DuplicateTestSessionRelative( Guid testSessionId, int seconds, Guid newTestSessionId, string newTestSessionName, DateTime newTestSessionCreatedOn);
    }
}
